//
//  PreRecordController.m
//  Lead
//
//  Created by shouhan on 2018/8/31.
//  Copyright © 2018年 陈永发. All rights reserved.
//

#import "PreRecordController.h"
#import "PayPreCell.h"
#import "PreModel.h"
@interface PreRecordController ()<UITableViewDelegate,UITableViewDataSource>
{
    int pageindex;
}
@property (weak, nonatomic) IBOutlet UITableView *preTableView;
@property (nonatomic, strong) NSMutableArray * arrDataSource;

@end

@implementation PreRecordController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.preTableView registerNib:[UINib nibWithNibName:@"PayPreCell" bundle:nil] forCellReuseIdentifier:@"PayPreCell"];
    
    self.bottomLayout.constant = KNAVIGATIONBARHEIGHT;
    
    pageindex = 1;
    [self getIntegralDetailList:YES];
    self.preTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refresh)];
    
    self.preTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arrDataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    PayPreCell * cell  = [tableView dequeueReusableCellWithIdentifier:@"PayPreCell"];
    cell.preModel = self.arrDataSource[indexPath.row];
    return cell;
}
-(void)refresh
{
    pageindex = 1;
    [self getIntegralDetailList:YES];
}
-(void)loadMore
{
    pageindex ++;
    [self getIntegralDetailList:NO];
}

- (void)getIntegralDetailList:(BOOL)isRefresh{
    
    
    [PPNetworkHelper GET:@"/data/api/withdraw_recording" parameters:@{@"pageindex":[NSString stringWithFormat:@"%d",pageindex],@"count":@"20"} cache:NO encrypt:NO decode:NO responseCache:^(id responseCache) {
        
    } success:^(id result) {
        
        if (isRefresh) {
            [self.arrDataSource removeAllObjects];
        }
        if ([result[@"success"] boolValue] == YES) {
            [self.arrDataSource addObjectsFromArray:[PreModel mj_objectArrayWithKeyValuesArray:result[@"data"]]];
        }
        
        [self.preTableView reloadData];
        [self.preTableView.mj_header endRefreshing];
        [self.preTableView.mj_footer endRefreshing];

    } failure:^(NSError *error) {
        [self.preTableView.mj_header endRefreshing];
        [self.preTableView.mj_footer endRefreshing];
    }];
    
    
}

- (NSMutableArray *)arrDataSource{
    if (!_arrDataSource) {
        _arrDataSource = [NSMutableArray array];
    }
    
    return _arrDataSource;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



@end
